#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob
import sys, os
parpath=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(parpath)

import games

#游戏模块列表
gameModules=[]

def updateGameModules():
    '''更新游戏模块列表，采用读取游戏模块文件夹的方式动态导入'''
    global gameModules
    gamesfile=os.path.abspath(games.__file__)
    gamespath=os.path.dirname(gamesfile)
    files=glob.glob(gamespath+'/*.*')
    mGameNames=['games.'+os.path.basename(f).split('.')[0] for f in files]
    mGameNames=list(set(mGameNames))
    mGameNames.remove('games.__init__')
    mGameNames.remove('games.general')
    
    for m in mGameNames:
        __import__(m)
    gameModules=[sys.modules[n] for n in mGameNames]

if __name__ == '__main__':
    updateGameModules()
    print gameModules
